/*global Ext, Portal*/
Ext.ns('Portal.renderer');

Ext.apply(Portal.renderer, {
	// transforms the value into image
	sex : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.sex) {
			case '2' :
				result = "<img src='resources/icons/fam/icons/user_suit.png'   ALIGN='left'/> ";
				break;
			case '1' :
				result = "<img src='resources/icons/fam/icons/user_female.png'   ALIGN='left'/> ";
				break;
			default :
				result = "<img src='resources/icons/fam/icons/help.png'   ALIGN='left'/> ";
				break;
		}
		return result + data;
	},

	sexText : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (data) {
			case '2' :
				result = "M";
				break;
			case '1' :
				result = "F";
				break;
			default :
				result = "N";
				break;
		}
		return result;
	},

	delNull : function(data) {
		if(data === null) {
			data = "";
		}
		return data;
	},

	priority : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';

		metadata.attr = 'ext:qtip="' + record.data.obs + '" ';
		switch (data) {
			case '0' :
				result = "<img src='resources/icons/fam/icons/obs_white.png'  ext:qtip='" + record.data.obs + "'   /> ";
				break;
			case '1' :
				result = "<img src='resources/icons/fam/icons/obs_yellow.png'   /> ";
				break;
			case '2' :
				result = "<img src='resources/icons/fam/icons/obs_green.png'   /> ";
				break;
			case '3' :
				result = "<img src='resources/icons/fam/icons/obs_blue.png'   /> ";
				break;
			case '4' :
				result = "<img src='resources/icons/fam/icons/obs_red.png'   /> ";
				break;
			case '5' :
				result = "<img src='resources/icons/fam/icons/obs_purple.png'   /> ";
				break;
			case '6' :
				result = "<img src='resources/icons/fam/icons/obs_black.png'   /> ";
				break;
		}

		if((record.data.unsubscribed) && (record.data.unsubscribed == 1)) {
			result += "<img src='resources/icons/fam/icons/email_delete.png' TITLE='DEZABONAT'  /> ";

		} else {
			result += "";
		}

		return result;
	},

	tooltipRenderer : function(data, metadata, record, rowIndex, columnIndex, store) {
		metadata.attr = 'ext:qtip="' + data + '" ';
		return data;
	},

	//renderer folosit la corector
	//in functie de tipul de data adusa ( obiect sau subiect) adaug un icon.. tipul
	// de data este dat de 'level'
	corrector : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.level) {
			case '0' :
				result = "<img src='resources/icons/fam/icons/package.png' ALIGN='left' /> " + data;
				break;
			case '1' :
				result = "<img src='resources/icons/fam/icons/page_green.png'  style='margin-left:20px'  ALIGN='left'/> " + data;
				break;
		}
		return result;
	},

	text2thumb : function(val) {
		return "<img src='resources/uploads/thumb/" + val + "' />";
	},

	text2link : function(val) {
		if(val) {
			return "<a target='_blank' href='resources/uploads/attach/" + val + "'>" + val + "</a>";
		}
		return val;
	},

	name2path : function(val) {
		return "resources/uploads/full/" + val;
	},

	mailStatus : function(data, metadata, record, rowIndex, columnIndex, store) {
		if(data) {
			var stat = record.data.status;
			if(stat == '1') {
				return "<font color=red>" + data + "</font>";
			}
			if(stat == '10') {
				return "<font color=green>" + data + "</font>";
			}
			return data;
		} else {
			return "";
		}
	},

	mailStatus2 : function(data, metadata, record, rowIndex, columnIndex, store) {
		if(data) {
			var stat = record.data.status2;
			if(stat == '1') {
				return "<font color=red>" + data + "</font>";
			}
			if(stat == '10') {
				return "<font color=green>" + data + "</font>";
			}
			return data;
		} else {
			return "";
		}
	},

	mailerStatus : function(data, metadata, record, rowIndex, columnIndex, store) {
		metadata.attr = 'ext:qtip="Succes:' + record.data.success + ', Erori:' + record.data.failure + ' " ';
		return "<font color=green>" + record.data.success + "</font>/<font color=red>" + record.data.failure + "</font>";
	},

	available : function(data, metadata, record, rowIndex, columnIndex, store) {
		if(data == "1") {
			return "<font color=green >DA</font>";
		}
		return "<font color=red >NU</font>";
	},

	top : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (rowIndex) {
			case 0 :
				result = "<img src='resources/img/premiu/1.gif'   border=0 width=27 /> ";
				break;
			case 1 :
				result = "<img src='resources/img/premiu/2.gif'   border=0 width=27  /> ";
				break;
			case 2:
				result = "<img src='resources/img/premiu/3.gif'   border=0 width=27  /> ";
				break;
			case 3:
				result = "<img src='resources/img/premiu/4.gif'   border=0 width=27  /> ";
				break;
			case 4 :
				result = "<img src='resources/img/premiu/5.gif'   border=0 width=27  /> ";
				break;
			case 5 :
				result = "<img src='resources/img/premiu/6.gif'   border=0 width=27  /> ";
				break;
			case 6 :
				result = "<img src='resources/img/premiu/7.gif'   border=0 width=27  /> ";
				break;
			case 7 :
				result = "<img src='resources/img/premiu/8.gif'   border=0 width=27  /> ";
				break;
			case 8 :
				result = "<img src='resources/img/premiu/10.gif'   border=0 width=27  /> ";
				break;
			case 9 :
				result = "<img src='resources/img/premiu/11.gif'   border=0 width=27  /> ";
				break;
			case 10 :
				result = "<img src='resources/img/premiu/12.gif'   border=0 width=27  /> ";
				break;
			case 11 :
				result = "<img src='resources/img/premiu/13.gif'   border=0 width=27  /> ";
				break;
			case 12 :
				result = "<img src='resources/img/premiu/14.gif'   border=0 width=27  /> ";
				break;
			case 13 :
				result = "<img src='resources/img/premiu/15.gif'   border=0 width=27  /> ";
				break;
			case 14 :
				result = "<img src='resources/img/premiu/16.gif'   border=0 width=27  /> ";
				break;
			case 15 :
				result = "<img src='resources/img/premiu/17.gif'   border=0 width=27  /> ";
				break;
		}
		return result;
	},

	topDetail : function(data, metadata, record, rowIndex, columnIndex, store) {

		var result = data;
		metadata.attr = 'ext:qtip="' + "Create: " + record.data.create + ", Modificate:" + record.data.mod + '" ';

		return result;
	},

	importCompany : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(record.data.settings[0] == '0') {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + record.data.company + '" ';
		return result;
	},

	importSex : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		switch (record.data.sex) {
			case '1' :
				result = "F";
				break;
			case '2' :
				result = "M";
				break;
			case '3' :
				result = "-";
				break;
			default :
				metadata.css = 'import-red-row';
				break;
		}
		return result;
	},

	importDomain : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.domain, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importSubdomain : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.subdomain, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importPosition : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.position, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importSubposition : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.subposition, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importDivision : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.division, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importCity : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.city, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importCounty : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.county, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importClient : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.client, result);
		} else {
			metadata.css = 'import-green-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importAge : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.age, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importIncome : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.income, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importAvailable : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.available, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importPriority : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.priority, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importPresent : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]$/;

		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.available, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importEmployees : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.employee, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importTurnover : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = data;
		if(result === null) {
			return "";
		}
		var numericExpression = /^[0-9]+$/;
		if(result.match(numericExpression)) {
			result = Portal.object.dataView(Portal.object.turnover, result);
		} else {
			metadata.css = 'import-red-row';
		}
		metadata.attr = 'ext:qtip="' + result + '" ';
		return result;
	},

	importObs : function(data, metadata, record, rowIndex, columnIndex, store) {
		metadata.attr = 'ext:qtip="' + data + '" ';
		return data;
	},

	/******CAMPAIGN******/
	campaignNameType : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.extern) {
			case '1' :
				result = "<img src='resources/icons/fam/icons/folder_user.png' TITLE='LISTA EXTERNA'  ALIGN='left'/> ";
				break;
			case '0' :
				result = "<img src='resources/icons/fam/icons/group.png' TITLE='BAZA DE DATE'  ALIGN='left'/> ";
				break;
			default :
				result = "";
				break;
		}
		return result + data;
	},

	campaignSubscribe : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.unsubscribed) {
			case '1' :
				result = "<img src='resources/icons/fam/icons/email_delete.png' TITLE='DEZABONAT'  ALIGN='left'/> ";
				break;
			case '0' :
				result = "<img src='resources/icons/fam/icons/email.png' TITLE='ABONAT'  ALIGN='left'/> ";
				break;
			default :
				result = "";
				break;
		}
		return result;
	},

	/**** MAILER TASK ****/
	mailerTaskStatus : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.mailer_task_status) {
			case '1' :
				result = "<img src='resources/icons/fam/icons/clock_pause.png'   ALIGN='left'/> ";
				break;
			case '0' :
				result = "<img src='resources/icons/fam/icons/clock_play.png' ALIGN='left'/> ";
				break;
			case '10' :
				result = "<img src='resources/icons/fam/icons/accept.png' ALIGN='left'/> ";
				break;
			default :
				result = "";
				break;
		}
		return result;
	},

	/**** MAILER REPORT ****/
	mailerEmailStatus : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.status) {
			case '21' :
				result = "<img src='resources/icons/fam/icons/bullet_green.png'   ALIGN='left'/> ";
				break;
			case '1' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '2' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '3' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '12' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '100' :
				result = "<img src='resources/icons/fam/icons/accept.png' ALIGN='left'/> ";
				break;
			case '11' :
				result = "<img src='resources/icons/fam/icons/email_delete.png' ALIGN='left'/> ";
				break;
			default :
				result = "";
				break;
		}
		metadata.attr = 'ext:qtip="' + record.data.descriere + '" ';
		return result;
	},

	mailerEmailStatus2 : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.status2) {
			case '21' :
				result = "<img src='resources/icons/fam/icons/bullet_green.png'   ALIGN='left'/> ";
				break;
			case '1' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '2' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '3' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '12' :
				result = "<img src='resources/icons/fam/icons/exclamation.png'   ALIGN='left'/> ";
				break;
			case '100' :
				result = "<img src='resources/icons/fam/icons/accept.png' ALIGN='left'/> ";
				break;
			case '11' :
				result = "<img src='resources/icons/fam/icons/email_delete.png' ALIGN='left'/> ";
				break;
			default :
				result = "";
				break;
		}

		metadata.attr = 'ext:qtip="' + record.data.descriere2 + '" ';
		return result;
	},

	//pentru afisare status mailer ( modul programari mailer)
	activeMailer : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (record.data.mailer_task_status) {
			case '1' :
				result = "<img src='resources/icons/fam/icons/clock_pause.png'   ALIGN='left'/> ";
				metadata.attr = 'ext:qtip="Task pauza"';
				break;
			case '10' :
				result = "<img src='resources/icons/fam/icons/accept.png'   ALIGN='left'/> ";
				metadata.attr = 'ext:qtip="Task finalizat"';
				break;
			case '0' :
				result = "<img src='resources/icons/fam/icons/clock_go.png'   ALIGN='left'/> ";
				metadata.attr = 'ext:qtip="Task pornit"';
				break;
			default :
				result = "<img src='resources/icons/fam/icons/accept.png'   ALIGN='left'/> ";
				metadata.attr = 'ext:qtip="Status necunoscut"';
				break;
		}
		return result;
	},

	teleLog : function(data, metadata, record, rowIndex, columnIndex, store) {
		var result = '';
		switch (data) {
			case 'email' :
				result = "<img src='resources/icons/fam/icons/email.png'  ALIGN='left'/> ";
				break;
			case 'answer_insert' :
			case 'answer_mod' :
				result = "<img src='resources/icons/fugue/icons/fugue_question_frame.png'  ALIGN='left'/> ";
				break;
			case 'contact_mod' :
				result = "<img src='resources/icons/fam/icons/user.png'  ALIGN='left'/> ";
				break;
			case 'prog_add' :
				result = "<img src='resources/icons/fam/icons/clock.png'  ALIGN='left'/> ";
				break;
			default :
				result = " ";
				break;
		}
		return result;
	},

	mailerTaskStatistic : function(data, metadata, record, rowIndex, columnIndex, store) {

		return ['<b>Abonati</b> : ', record.json.total_contacte, '<br>',
		'<b>Email 1 de trimis</b> : ', record.json.total_email1, '<br>', 
		'<b>Email 2 de trimis </b> : ', record.json.total_email2, '<br>',
		'<b>Total de trimis</b> : ', record.json.total_de_trimis, '<br>',
		'<b>_________________ </b>', '<br>',
		'<b>Email 1 trimis succes</b> : ', record.json.email1_trimis_succes, '<br>', 
		'<b>Email 2 trimis succes</b> : ', record.json.email2_trimis_succes, '<br>', 
		'<b>Email 1 erori</b> : ', record.json.email1_netrimis, '<br>',
		'<b>Email 2 erori</b> : ', record.json.email2_netrimis, '<br>',
		'<b>_________________ </b>', '<br>',
		'<b>Emailuri ramase de trimis</b> : ', record.json.email_ramas, '<br>'		
		].join('');

	}

});
